package com.example.wod.retrofitdemo;

import com.example.wod.retrofitdemo.Bean.GetCapital;
import com.example.wod.retrofitdemo.Bean.Login;
import com.example.wod.retrofitdemo.Bean.Upload;

import java.io.File;
import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Query;

/**
 * Created by Wod on 2016/3/4.
 */
public interface ApiService {
    @FormUrlEncoded
    @POST("/index.php?m=User&c=Public&a=login")
    Call<Login> login(@Field("uname") String uname, @Field("password") String password);

    @POST("/index.php?m=Bonus&c=Capital&a=get_capital")
    Call<GetCapital> getCapital();

    @GET("/index.php?m=User&c=Energy&a=energy_info")
    Call<Login> geteninfo(@Query("user_key") String user_key);


    //文件上传取决于后台如何接受
    //参考
    //https://futurestud.io/blog/retrofit-2-how-to-upload-files-to-server#comment-2415543624

    @Multipart
    @POST("/index.php?m=System&c=Upload&a=upload")
    Call<Upload> upload(@Part("*\"; filename=\".png\" ") RequestBody fileRequest);

    //这写法是错误的
    @Multipart
    @POST("/index.php?m=System&c=Upload&a=upload")
    Call<Upload> upload(@Part("portrait\"; filename=\"messenger_01.*\" ") File fileRequest);

    //批量上传
    @Multipart
    @POST("/index.php?m=System&c=Upload&a=upload")
    Call<Upload> upload(@PartMap Map<String, RequestBody> params);
}
